Phase 6a: DataPact Client β Implementation Plan
TODO
phase6/datapact-client β httpx DataPact API client
Scope
cmmc/services/datapact_client.pyβDataPactClientclasstests/test_datapact_client.pyβ tests usingrespxto mock httpx
Design
DataPactClient class
- Constructor:
__init__(base_url, api_key, timeout)with defaults from config - Methods:
get_contracts()β list of contractsget_contract(contract_id)β single contractget_contract_compliance(contract_id)β compliance data- Uses
httpx.AsyncClientinternally for non-blocking I/O - Sends
Authorization: Bearer {api_key}header - Custom exceptions:
DataPactConnectionError,DataPactAuthError,DataPactNotFoundError,DataPactRateLimitError,DataPactError
Error Handling
httpx.TimeoutExceptionβDataPactConnectionErrorhttpx.ConnectErrorβDataPactConnectionError- 401/403 β
DataPactAuthError - 404 β
DataPactNotFoundError - 429 β
DataPactRateLimitError - 5xx β
DataPactError
Testing
- Use
respxlibrary to mock httpx requests - Test each method with success and error scenarios
- Test timeout handling
- Test auth header sent correctly
Files
| File | Change |
|---|---|
cmmc/services/datapact_client.py |
New β client class |
tests/test_datapact_client.py |
New β tests |
docs/PRD/PRD-006-datapact-integration.md |
New β PRD |